package com.example.controller;

import com.example.context.BaseContext;
import com.example.dto.CommentDTO;
import com.example.dto.PageDTO;
import com.example.entity.Comment;
import com.example.query.CommentQuery;
import com.example.result.Result;
import com.example.service.ICommentService;
import com.example.vo.CommentVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@Slf4j
@RequiredArgsConstructor
public class CommentController {

    private final ICommentService commentService;

    /*
    * 添加评论
    * @param commentDTO
    * @return
    * */
    @PostMapping("/add")
    public Result addComment(@RequestBody CommentDTO commentDTO) {
        log.info("添加评论"+commentDTO);
        commentService.addComment(commentDTO);
        return Result.success();
    }

    /*
    * 查看评论
    * @param commentDTO
    * @return
    * */
    @GetMapping("/page")
    public Result<PageDTO<CommentVO>> getComment(CommentQuery commentQuery){
        log.info("查看评论"+commentQuery);
        return commentService.QueryCommentpage(commentQuery);
    }

    /*
    * 删除评论
    * @param id
    * @return
    * */
    @DeleteMapping
    public Result delete(Long id) {
        log.info("删除评论"+id);
        commentService.removeComment(id);
        return Result.success();
    }

}
